//
//  SettingViewController.m
//  A段项目
//
//  Created by dllo on 16/3/9.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "SettingViewController.h"
#import "SetProfressionCell.h"
#import <UIImageView+WebCache.h>

@interface SettingViewController ()<UITableViewDelegate,UITableViewDataSource,SetProfressionalDelegate>

@property (nonatomic, retain) UITableView *tableView;

@end

@implementation SettingViewController

- (void)dealloc {
    
    [_tableView release];
    
    [super dealloc];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.navigationItem.title = @"设置";
    [self creatTableView];
    
    
    
}

- (void)creatTableView {
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:0];
    
    [self.view addSubview:self.tableView];
    
    self.tableView.delegate = self;
    
    self.tableView.dataSource  = self;
    
    [self.tableView registerClass:[SetProfressionCell class] forCellReuseIdentifier:@"pool1"];
    
    [_tableView release];
    
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 2;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    

    
  SetProfressionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool1"];
    
    cell.delegate = self;
    
    cell.selectionStyle = 0;
    
    if (indexPath.row == 1) {
        
        cell.leftLabel.text = @"夜间模式";
        
        
    }else {
        
         cell.leftLabel.text = @"清空缓存";
        
    }
    

    return cell;
}

- (void)touchSwitch:(SetProfressionCell *)cell {
    
   
    
    if ([cell.leftLabel.text  isEqual: @"清空缓存"]) {
        
        // 获取缓存大小
        NSUInteger size = [[SDImageCache sharedImageCache] getSize];
        
        float cacheSize = size / 1024.0 / 1024.0;
        
        NSString  *string = [NSString stringWithFormat:@"%.2fM",cacheSize];
        
        NSString *info = [NSString stringWithFormat:@"你有 %@ 的缓存,点击确定清除",string];
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:info preferredStyle:1];
        
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:0 handler:^(UIAlertAction * _Nonnull action) {
            
             [[SDImageCache sharedImageCache] clearDisk];
            
            [cell.rightSwitch setOn:NO];
            
            UIAlertController *alert2 = [UIAlertController alertControllerWithTitle:@"提示" message:@"您已成功清除缓存" preferredStyle:1];
            
            [self presentViewController:alert2 animated:YES completion:^{
                
                [alert2 dismissViewControllerAnimated:YES completion:nil];
                
            }];
            
            
        }];
        
        UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:1 handler:^(UIAlertAction * _Nonnull action) {
            
             [cell.rightSwitch setOn:NO];
        }];
        
        [alert addAction:action1];
        [alert addAction:action2];
        
        [self presentViewController:alert animated:YES completion:^{

            
            
        }];
        
        
    
    }else {
        
        
        
    }
    
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
